#include "widget.h"
#include "ui_widget.h"
#include "QLineEdit"
#include "QRegExp"
#include "QRegExpValidator"
#include "QValidator"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->lineEdit->setEchoMode(QLineEdit::Normal);
    ui->lineEdit->setPlaceholderText("请输入用户名");
    ui->lineEdit->setClearButtonEnabled(true);

    ui->lineEdit_2->setEchoMode(QLineEdit::Password);
    ui->lineEdit_2->setPlaceholderText("请输入密码");
    ui->lineEdit_2->setClearButtonEnabled(true);
    //QRegExp reg1("^(?=.*[A-Z])(?=.*\d).{8,}$");
    //ui->lineEdit_2->setValidator(new QRegExpValidator(reg1));


    ui->lineEdit_3->setEchoMode(QLineEdit::Password);
    ui->lineEdit_3->setPlaceholderText("请确认你的密码");
    ui->lineEdit_3->setClearButtonEnabled(true);
    //QRegExp reg2("^(?=.*[A-Z])(?=.*\d).{8,}$");
    //ui->lineEdit_3->setValidator(new QRegExpValidator(reg2));

    ui->pushButton->setText("提交");
    ui->pushButton->setEnabled(false);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_lineEdit_2_textEdited(const QString &arg1)
{
    //QString content = arg1;
    //int pos = 0;
    //if(ui->lineEdit_2->validator()->validate(content,pos) == QValidator::Acceptable)
        this->compare();
}

void Widget::on_lineEdit_3_textEdited(const QString &arg1)
{
    //QString content = arg1;
    //int pos = 0;
    //if(ui->lineEdit_3->validator()->validate(content,pos) == QValidator::Acceptable)
        this->compare();
}

void Widget::compare()
{
    const QString s2 = ui->lineEdit_2->text();
    const QString s3 = ui->lineEdit_3->text();
    if(s2.isEmpty() && s3.isEmpty())
        ui->label->setText("密码为空");
    else if(s2 != s3)
    {
        ui->label->setText("密码不一致");
        ui->pushButton->setEnabled(false);
    }
    else
    {
        ui->label->setText("密码一致");
        ui->pushButton->setEnabled(true);
    }
}


